/*
 * @Author: qin
 * @Date:   2018-08-28
 * +----------------------------------------------------------------------
 * | admin [ 后台管理系统公共配置信息 ]
 * | 匹配字典,接收目标的value，返回可选
 * +----------------------------------------------------------------------
 */
layui.define(['jquery','jsDictFile'], function (exports) {
    var $ = layui.jquery;
    var jsDictFile = layui.jsDictFile;
    var matchDict = {
        //返回目标数组
        array: function (target, dictData) {
            var data = $(dictData).filter(function (index, item) {
                return parseInt(item.value) == parseInt(target);
            });
            return data;
        },
        //返回目标对象
        data: function (target, dictData) {
            var data = $(dictData).filter(function (index, item) {
                return item.value == target;
            });
            return data[0];
        },
        //返回目标name
        name: function (targetItem, dictData) {
            var data = $(jsDictFile[dictData][0].childrens).filter(function (index, item) {
                return item.value == targetItem;
            });
            return data.length > 0 ? data[0].name : '-';
        }
    };
    exports('matchDict', matchDict);
});
